//https://leetcode.cn/problems/longest-arithmetic-subsequence-of-given-difference/

class Solution {
public:
    int longestSubsequence(vector<int>& arr, int difference) {
        int n = arr.size(), ans = 1;
        unordered_map<int, int> hash;
        hash[arr[0]] = 1;
        for(int i = 1; i < n; i++)
        {
            hash[arr[i]] = hash[arr[i] - difference] + 1;
            ans = max(ans, hash[arr[i]]);
        }
        return ans;

    }
};